#!/usr/bin/env bash
# -------------------------
#  Date    : 2020-11-15
#  Author  : Jieay
#  set -xv
# -------------------------

base_dir=`pwd`
pkg_dir=$base_dir/dist
frame_name=$1
echo -e "创建项目：${frame_name}"
code_dir=$pkg_dir/$frame_name
tar_name="pydj_code.tar.gz"

cd $base_dir && [ ! -d $pkg_dir ] && mkdir -p $pkg_dir
cd $base_dir && cp -r frame_server $code_dir
cd $code_dir && mv frame_server $frame_name

cd $pkg_dir
sed -i "s/frame_server/${frame_name}/g" $frame_name/config_dev
sed -i "s/frame_server/${frame_name}/g" $frame_name/config_dist
sed -i "s/frame_server/${frame_name}/g" $frame_name/manage.py
sed -i "s/frame_server/${frame_name}/g" $frame_name/$frame_name/celery.py
sed -i "s/frame_server/${frame_name}/g" $frame_name/README.md
sed -i "s/frame_server/${frame_name}/g" $frame_name/$frame_name/settings.py
sed -i "s/frame_server/${frame_name}/g" $frame_name/$frame_name/wsgi.py
sed -i "s/frame_server/${frame_name}/g" $frame_name/$frame_name/urls.py
sed -i "s/frame_server/${frame_name}/g" $frame_name/app/tasks/demo_test.py

cd $pkg_dir && [ -e $tar_name ] && rm -rf $tar_name
echo -e "压缩工程文件：${tar_name}"
cd $pkg_dir && tar -zcf $tar_name --exclude */__pycache__* $frame_name && rm -rf $frame_name
echo -e "项目脚手架文件已经制作完成，文件目录：${pkg_dir}"